package com.openatc.model.model;

import lombok.Data;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ：panleilei
 * @description
 * @modified By：
 * @version:
 * @date ：Created in 2023/3/30 9:50
 */
@Data
public class Channel {
    private Integer id;
    private String desc;
    private Integer controlsource;
    private Integer controltype;
    private Integer direction;
    private List<Integer> turn;
    private Integer type;
    private List<Integer> realdir;
    private Integer pacthresh; // 灯功率检测阈值
    private Integer peakhthresh; // 高功率故障阈值
    private Integer peaklthresh; // 低功率故障阈值
    private Integer voltthresh; // 灯电压检测阈值
    private static final Map<Integer,Channel> channels = new HashMap<>(16);
    static {
        Channel channel1 = Channel.createDefaultChannel(1,2,2,0,Arrays.asList(2));  // 东左通道
        Channel channel2 = Channel.createDefaultChannel(2,1,2,0,Arrays.asList(1));  // 东直通道
        Channel channel12 = Channel.createDefaultChannel(12,5,3,2,Arrays.asList(1));  // 东行人
        Channel channel5 = Channel.createDefaultChannel(5,6,2,0,Arrays.asList(14));  // 南左通道
        Channel channel6 = Channel.createDefaultChannel(6,5,2,0,Arrays.asList(13));  // 南直通道
        Channel channel9 = Channel.createDefaultChannel(9,4,2,0,Arrays.asList(6));  // 西左通道
        Channel channel16 = Channel.createDefaultChannel(16,3,3,2,Arrays.asList(3));  // 南行人
        Channel channel10 = Channel.createDefaultChannel(10,3,2,0,Arrays.asList(5));  // 西直通道
        Channel channel4 = Channel.createDefaultChannel(4,7,3,2,Arrays.asList(2));  // 西行人
        Channel channel13 = Channel.createDefaultChannel(13,8,2,0,Arrays.asList(10));  // 北左通道
        Channel channel14 = Channel.createDefaultChannel(14,7,2,0,Arrays.asList(9));  // 北直通道
        Channel channel8 = Channel.createDefaultChannel(8,1,3,2,Arrays.asList(4));  // 北行人
        channels.put(1,channel1);
        channels.put(2,channel2);
        channels.put(12,channel12);
        channels.put(5,channel5);
        channels.put(6,channel6);
        channels.put(9,channel9);
        channels.put(16,channel16);
        channels.put(10,channel10);
        channels.put(4,channel4);
        channels.put(13,channel13);
        channels.put(14,channel14);
        channels.put(8,channel8);
    }
    public static Channel getChannelById(Integer id) {
        return channels.get(id);
    }

    /**
     * 构建默认的通道对象
     * @param id
     * @param controlsource
     * @param controltype
     * @Param realdir
     * @return
     */
    public static Channel createDefaultChannel(int id, int controlsource, int controltype, int type, List<Integer> realdir) {
        Channel channel = new Channel();
        channel.setId(id);
        channel.setDesc("");
        channel.setControlsource(controlsource);
        channel.setControltype(controltype);
        channel.setDirection(0);
        channel.setType(type);
        channel.setRealdir(realdir);
        channel.setPacthresh(30);
        channel.setPeakhthresh(400);
        channel.setPeaklthresh(130);
        channel.setVoltthresh(50);
        return channel;
    }
}
